package com.intellagric.controller.module.trace_produce_warehouse;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.ProduceWarehouseVo;
import com.intellagric.pojo.TraceProduceWarehouse;
import com.intellagric.service.traceability.trace_produce_warehouse.ProduceWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/3
 * @DESC： 农产品库存信息管理
 */
@Controller
public class ProduceWarehouseController {

    @Autowired
    private ProduceWarehouseService produceWarehouseService;

    /**
     * 添加农产品库存信息
     * @Param produceWarehouse
     * @return ResponseMessage
     */
    @RequestMapping("/produce/warehouse/add")
    @ResponseBody
    public ResponseMessage add(TraceProduceWarehouse produceWarehouse) {
        //初始化信息
        produceWarehouse.setId(UUID.randomUUID().toString().replaceAll("-",""));
        produceWarehouse.setCreateDate(new Date());
        produceWarehouse.setUpdateDate(new Date());
        return produceWarehouseService.addProduceWarehouse(produceWarehouse);
    }

    /**
     * 删除农产品库存信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/produce/warehouse/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return produceWarehouseService.deleteProduceWarehouse(id);
    }

    /**
     * 修改农产品库存信息
     * @Param produceWarehouse
     * @return ResponseMessage
     */
    @RequestMapping("/produce/warehouse/edit")
    @ResponseBody
    public ResponseMessage edit(TraceProduceWarehouse produceWarehouse) {
        produceWarehouse.setUpdateDate(new Date());
        produceWarehouse.setCreateDate(null);
        return produceWarehouseService.editProduceWarehouse(produceWarehouse);
    }

    /**
     * 查询农产品库存信息
     * @return TraceProduceWarehouse
     */
    @RequestMapping("/produce/warehouse/{id}")
    @ResponseBody
    public TraceProduceWarehouse get(@PathVariable String id) {
        return produceWarehouseService.getProduceWarehouseById(id);
    }

    /**
     * 查询农产品库存信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/warehouse/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return produceWarehouseService.getProduceWarehouseList();
    }

    /**
     * 分页查询农产品库存信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/warehouse/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return produceWarehouseService.getProduceWarehousePage(page,limit);
    }

    /**
     * 分页查询农产品库存信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/warehouse/pageByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,String createBy) {
        return produceWarehouseService.getProduceWarehousePage(page,limit,createBy);
    }

    /**
     * 多条件查询农产品库存信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/warehouse/query")
    @ResponseBody
    public LayuiDataGridResult getQueryList(ProduceWarehouseVo produceWarehouseVo) {
        return produceWarehouseService.getProduceWarehouseByVo(produceWarehouseVo);
    }

}
